package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;
import com.aijk.ehm.dao.mybatis.EhmClassifySubscribeMapper;
import com.aijk.ehm.model.EhmClassifySubscribe;
import com.aijk.ehm.model.EhmClassifySubscribeExample;
import com.aijk.ehm.model.qo.EhmClassifySubscribeQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 标签订阅管理
 */
@Service
public class EhmClassifySubscribeService {
    private static Logger logger = LoggerFactory.getLogger(EhmClassifySubscribeService.class);

    @Autowired
    private EhmClassifySubscribeMapper mapper;

    public EhmClassifySubscribeExample getExample(EhmClassifySubscribeQo qo) {
        EhmClassifySubscribeExample example = new EhmClassifySubscribeExample();
        EhmClassifySubscribeExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if (Utils.isNotEmpty(qo.getCid())) criteria.andCidEqualTo(qo.getCid());
            if (Utils.isNotEmpty(qo.getCreater())) criteria.andCreaterEqualTo(qo.getCreater());
        }
        return example;
    }

    public int count(EhmClassifySubscribeQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(EhmClassifySubscribe bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(EhmClassifySubscribe bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public EhmClassifySubscribe findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<EhmClassifySubscribe> find(EhmClassifySubscribeQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<EhmClassifySubscribe> page(PagingRequest pagingRequest, EhmClassifySubscribeQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<EhmClassifySubscribe>(mapper.selectByExample(getExample(qo)));
    }

    public int delete(EhmClassifySubscribeQo qo){
        return mapper.deleteByExample(getExample(qo));
    }
}